//
//  InquiryViewController.swift
//  DianShangWen
//
//  Created by 周文轩 on 15/4/20.
//  Copyright (c) 2015年 &#21608;&#25991;&#36713;. All rights reserved.
//

import UIKit

class InquiryViewController: UIViewController, UITextViewDelegate, UIScrollViewDelegate {
    
    @IBOutlet weak var inquiryButton: UIButton!
    @IBOutlet weak var inquiryView: UIView!
    @IBOutlet weak var insertionButton: UIButton!
    @IBOutlet weak var insertionView: UIView!
    @IBOutlet weak var titleTextView: UITextView!
    @IBOutlet weak var lableTextView: UITextView!
    @IBOutlet weak var contentTextView: UITextView!
    @IBOutlet weak var deleteImageButton1: UIButton!
    @IBOutlet weak var deleteImageButton2: UIButton!
    @IBOutlet weak var deleteImageButton3: UIButton!
    
    @IBOutlet weak var inquiryScroller: UIScrollView!
    @IBOutlet weak var titleTextViewWidth: NSLayoutConstraint!
    @IBOutlet weak var lableTextViewWidth: NSLayoutConstraint!
    @IBOutlet weak var contentTextViewWidth: NSLayoutConstraint!
    @IBOutlet weak var inquiryScrollerViewWidth: NSLayoutConstraint!
    @IBOutlet weak var inquiryButtonWidth: NSLayoutConstraint!
    @IBOutlet weak var addImageWidth: NSLayoutConstraint!
    @IBOutlet weak var insertionImageButtonWidth: NSLayoutConstraint!
    @IBOutlet weak var limitLabelWidth: NSLayoutConstraint!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        inquiryScroller.delegate = self
        inquiryScrollerViewWidth.constant = UIScreen.mainScreen().bounds.size.width*2
        titleTextViewWidth.constant = UIScreen.mainScreen().bounds.size.width-26
        lableTextViewWidth.constant = UIScreen.mainScreen().bounds.size.width-26
        contentTextViewWidth.constant = UIScreen.mainScreen().bounds.size.width-26
        inquiryButtonWidth.constant = UIScreen.mainScreen().bounds.size.width-26
        addImageWidth.constant = UIScreen.mainScreen().bounds.size.width
        insertionImageButtonWidth.constant = UIScreen.mainScreen().bounds.size.width-26
        limitLabelWidth.constant = UIScreen.mainScreen().bounds.size.width-26
        
        createTextView()
        changeDeleteImageButton()

        // Do any additional setup after loading the view.
    }
    
    func createTextView() {
        titleTextView.delegate = self
        lableTextView.delegate = self
        contentTextView.delegate = self
    }
    
    func changeDeleteImageButton() {
        deleteImageButton1.layer.cornerRadius = 4.0
        deleteImageButton2.layer.cornerRadius = 4.0
        deleteImageButton3.layer.cornerRadius = 4.0
    }
    
    func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
        switch scrollView.contentOffset.x {
        case 0:
            inquiry()
        case self.view.frame.size.width:
            insertion()
        default:
            println("")
            
        }
    }
    
    func textViewDidBeginEditing(textView: UITextView) {
        textView.text = ""
    }
    
    func textViewDidEndEditing(textView: UITextView) {
        switch textView.tag {
        case 1:
            textView.text = "请输入标题，限20字"
        case 2:
            textView.text = "请输入标签，多个标签用逗号分隔，限5个标签，每个标签最多输入10个字"
        case 3:
            textView.text = "请清晰讲述您的问题，限1000字"
        default:
            println("")
        }
    }
    
    @IBAction func deleteImage(button: UIButton) {
        
    }
    
    @IBAction func inquiry() {
        inquiryButton.setTitleColor(ResourceProvider.sharedInstance.redColoer, forState: UIControlState.Normal)
        inquiryView.backgroundColor = ResourceProvider.sharedInstance.redColoer
        insertionButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        insertionView.backgroundColor = UIColor.whiteColor()
        
        inquiryScroller.contentOffset.x = 0
    }
    
    @IBAction func insertion() {
        insertionButton.setTitleColor(ResourceProvider.sharedInstance.redColoer, forState: UIControlState.Normal)
        insertionView.backgroundColor = ResourceProvider.sharedInstance.redColoer
        inquiryButton.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
        inquiryView.backgroundColor = UIColor.whiteColor()
        
        inquiryScroller.contentOffset.x = self.view.frame.size.width
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
